//
//  TMHomeVC.m
//  TMBD Movie App
//
//  Created by zhangkai on 2023/4/2.
//

#import "TMHomeVC.h"
#import <JXCategoryView/JXCategoryView.h>
#import "JXPagerView.h"
#import "TMHomeSubVC.h"
#import "TMNavView.h"
#import "TMAllHomeSubVC.h"
#import "TMNetworkManage.h"
#import "movieInfo-Swift.h"
#import "JXPagerListRefreshView.h"
//#import "TMDeviceInfo-Swift.h"
//#import "MoviesInfo-Swift.h"
CGFloat NaviBarHeight = 44;

@interface TMHomeVC ()<JXCategoryViewDelegate, JXPagerViewDelegate,JXPagerMainTableViewGestureDelegate>
@property (nonatomic, strong)JXPagerView *pagingView;
//@property(nonatomic,strong)
//@property (nonatomic, strong) HLUserCenterHeaderView *userHeaderView;
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) NSArray <NSString *> *titles;

@end

@implementation TMHomeVC
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    
    
    
    TMNavView *nav = [TMNavView new];
    nav.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:nav];
    
    self.titles = @[@"Movie",@"TV Shows",@"ALL"];

    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNavgationBarHeight+State_Bar_H, [UIScreen mainScreen].bounds.size.width, 56)];
    self.categoryView.titles = self.titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
//    self.categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#333333"];
//    self.categoryView.titleColor = [UIColor colorWithHexString:@"#A4A4A4"];
    self.categoryView.titleFont = [UIFont systemFontOfSize:16];
    self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
//    lineView.indicatorColor = [UIColor colorWithHexString:@"#009919"];
    lineView.indicatorWidth = 25;
    lineView.verticalMargin = 6;
    lineView.indicatorHeight = 4;
    _categoryView.indicators = @[lineView];

    self.pagingView = [[JXPagerListRefreshView alloc] initWithDelegate:self];
    self.pagingView.backgroundColor = [UIColor purpleColor];
    self.pagingView.mainTableView.backgroundColor = [UIColor yellowColor];
//    self.pagingView.pinSectionHeaderVerticalOffset = kTopHeight;
    [self.view addSubview:self.pagingView];
    self.pagingView.mainTableView.gestureDelegate = self;


    self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
    
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.pagingView.frame = CGRectMake(0, kNavgationBarHeight+State_Bar_H, [UIScreen mainScreen].bounds.size.width, kScreenH-kNavgationBarHeight-State_Bar_H-56);
}



#pragma mark - JXPagingViewDelegate

- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
    return [UIView new];
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    return 1;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return 56;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return self.categoryView;
}

- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
    return self.titles.count;
}

- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
    
    
    if (index == 2) {
        TMAllHomeSubVC *VC = [[TMAllHomeSubVC alloc] init];
        return VC;
    }else{
        
        TMHomeSubVC *friendSubView = [[TMHomeSubVC alloc] init];
        if(index == 0){
            friendSubView.type = @"277";
        }else{
            friendSubView.type = @"273";
        }
        return friendSubView;
    }
    


}

- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}


- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    //禁止categoryView左右滑动的时候，上下和左右都可以滚动
    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
        return NO;
    }
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}




@end
